"""必须登陆用户才能查询信息定义装饰器"""
from flask import g


def loginrequired(func):

    def wrapper(*args, **kwargs):
        # user_id = None
        user_id = g.user_id
        if user_id is None:
            return {'message': 'Please Login'}, 401
        elif g.refresh:
            return {'message': 'Do not use refresh token.'}, 403
        else:
            return func(*args, **kwargs)

    return wrapper